package com.xh3140.android.widget.table;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;

public class NestedTableRow extends LinearLayoutCompat {
    public NestedTableRow(@NonNull Context context) {
        this(context, null);
    }

    public NestedTableRow(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NestedTableRow(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(HORIZONTAL);
        setShowDividers(SHOW_DIVIDER_MIDDLE);
        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(Color.BLACK);
        drawable.setSize(1, 1);
        setDividerDrawable(drawable);
    }

    public void addTableCellView(@NonNull View tableCellView) {
        addView(tableCellView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    public void addTableCellView(@NonNull View tableCellView, float weight) {
        addView(tableCellView, new LayoutParams(0, LayoutParams.MATCH_PARENT, weight));
    }

    public void addNestedTableView(@NonNull NestedTableView tableView) {
        addView(tableView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    public void addNestedTableView(@NonNull NestedTableView tableView, float weight) {
        addView(tableView, new LayoutParams(0, LayoutParams.MATCH_PARENT, weight));
    }
}
